<template>
  <el-dialog
    :title="viewMode ? '查看填报数据' : '在线填报'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="65%"
    fullscreen>
    <el-form class="cop-report3" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <table style="width: 900px;" class="table table-bordered">
			<tbody><tr>
				<td colspan="10" class="title">
					林业合作社基本信息
				</td>
			</tr>
			<tr>
				<td style="width: 140px;">
					合作社名称
				</td>
				<td colspan="9">
					<input v-model="dataForm.copName"  type="text" class="form-control" name="cooperativeName">
				</td>
			</tr>
			<tr>
				<td>
					创建人姓名
				</td>
				<td colspan="4">
					<input v-model="dataForm.createName" type="text" class="form-control" name="relName">
				</td>
				<td style="width: 140px;">
					创建人年龄
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.createAge" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="age">
						<span class="input-group-addon">岁</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					创建人性别
				</td>
				<td colspan="4">
					<input v-model="dataForm.createSex" type="text" class="form-control" name="sex">
				</td>
				<td>
					创建人受教育程度
				</td>
				<td colspan="4">
					<input v-model="dataForm.createEdu" type="text" class="form-control" name="educationalLevel">
				</td>
			</tr>
			<tr>
				<td>
					创建人职业
				</td>
				<td colspan="4">
					<input v-model="dataForm.createPosition" type="text" class="form-control" name="occupation">
				</td>
				<td>
					创建人年收入
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.createIncome" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="yearIncome">
						<span class="input-group-addon">万元</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					合作社类型
				</td>
				<td colspan="9">
					<input v-model="dataForm.copType" type="radio" value="行业协会带动型" name="type" id="profession"><label name="Profession">行业协会带动型（行业协会为依托，“协会-基地-农户”模式）</label><br>
					<input v-model="dataForm.copType" type="radio" value="种养大户创办型" name="type" id="bigFarmers"><label name="BigFarmers">种养大户创办型（种养大户或经营能手牵头，农户参加，开展产前、产中、产后全程服务）</label><br>
					<input v-model="dataForm.copType" type="radio" value="基层组织创办型" name="type" id="grassrootOrganization"><label name="GrassrootOrganization">基层组织创办型（村基层组织根据产业优势和社会发展需要，创办的合作社）</label><br>
					<input v-model="dataForm.copType" type="radio" value="公司企业领办型" name="type" id="companyLeadType"><label name="CompanyLeadType">公司企业领办型（由规模较大的公司改制成合作社）</label><br>
					<input v-model="dataForm.copTypeOther" type="checkbox" value="typeOther" name="other" class="otherCheckbox" id="other"><label name="Other">其他类型</label> <input type="text" class="form-control" name="typeOther" v-model="dataForm.copTypeValue"><br>
				</td>
			</tr>
			<tr>
				<td>
					注册资本
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.regAssert" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="registeredCapital"> 
						<span class="input-group-addon">万元</span>
					</div>
				</td>
				<td>
					成立时间
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.beginYear" type="text" class="form-control" name="gmtCreate">
						<span class="input-group-addon">年</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					营业收入
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.busIncome" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="businessIncome">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
				<td>
					营业成本
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.busCost" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="businessCost">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					合作社是否采取股份制
				</td>
				<td colspan="4">
					<input v-model="dataForm.isStock" type="radio" value="是" name="ifShares"><label>是</label>
					<input v-model="dataForm.isStock" type="radio" value="否" name="ifShares"><label>否</label>
				</td>
				<td>
					若是：农户占股比重
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.farmerRate" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="farmerProportion">
						<span class="input-group-addon">%</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					合作社资金来源
				</td>
				<td colspan="9">
					<input v-model="dataForm.moneySource" type="radio" value="国家或地方财政投入" name="fundsSource"><label name="Revenue">国家或地方财政投入</label>
					<input v-model="dataForm.moneySource" type="radio" value="银行贷款" name="fundsSource"><label name="Bank">银行贷款</label>
					<input v-model="dataForm.moneySource" type="radio" value="企业自筹" name="fundsSource"><label name="Company">企业自筹</label>
					<input v-model="dataForm.moneySource" type="radio" value="社会捐助" name="fundsSource"><label name="Sociology">社会捐助</label>
					<input v-model="dataForm.moneySource" type="radio" value="要素折股" name="fundsSource"><label name="FoldingStock">要素折股</label><br>
					<input v-model="dataForm.moneySourceOther" type="checkbox" value="fundsSourceOther" class="otherCheckbox" id="otherCapital" name="OtherCapital"><label name="OtherCapital">其他类型</label> <input v-model="dataForm.moneySourceValue" name="fundsSourceOther" type="text" class="form-control"><br>
				</td>
			</tr>
			<tr>
				<td>
					获财政扶持资金总额
				</td>
				<td colspan="9">
					<div class="input-group">
						<input v-model="dataForm.govSupport" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');"  type="text" class="form-control" name="supportFunds">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="10" class="title">
					合作社主营业务情况
				</td>
			</tr>
			<tr>
				<td colspan="2">
					主营业务
				</td>
				<td colspan="8">
					<input v-model="dataForm.mainBus" type="radio" value="林木、林产品生产种植环节" name="mainBusiness"><label name="ForestProduct">林木、林产品生产种植环节</label>
					<input v-model="dataForm.mainBus" type="radio" value="林产品加工环节" name="mainBusiness"><label name="Machining">林产品加工环节</label>
					<input v-model="dataForm.mainBus" type="radio" value="林产品销售环节" name="mainBusiness"><label name="Sale">林产品销售环节</label>
					<input v-model="dataForm.mainBus" type="radio" value="林产品生产、加工、销售一体化 " name="mainBusiness"><label name="Integrated">林产品生产、加工、销售一体化</label>
					<input v-model="dataForm.mainBus" type="radio" value="土地流转" name="mainBusiness"><label name="Soil">土地流转</label><br>
					<input v-model="dataForm.mainBus" type="radio" value="技术指导服务" name="mainBusiness"><label name="TechnicalGuidance">技术指导服务</label>
					<input v-model="dataForm.mainBusOther" type="checkbox" value="mainBusinessOther" class="otherCheckbox" name="mainBusinessOtherCheckbox"><label name="OtherBusiness">其他，请备注</label><input v-model="dataForm.mainBusValue" type="text" name="mainBusinessOther" class="form-control"><br>
				</td>
			</tr>
			<tr>
				<td>
					合作社经营林地面积
				</td>
				<td colspan="3">
					<div class="input-group">
						<input v-model="dataForm.busArea" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="forestryArea">
						<span class="input-group-addon">亩</span>
					</div>
				</td>
				<td colspan="5">
					主营产品销售收入
				</td>
				<td>
					<div class="input-group">
						<input v-model="dataForm.saleIncome" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="salesRevenue">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					主营产品利润额
				</td>
				<td colspan="3">
					<div class="input-group">
						<input v-model="dataForm.prodProfit" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="profitMargin">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
				<td colspan="5">
					主营产品利润率
				</td>
				<td>
					<div class="input-group">
						<input v-model="dataForm.profitRate" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="profitMarginProportion">
						<span class="input-group-addon">%</span>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="10" class="title">
					合作社成员及收益
				</td>
			</tr>
			<tr>
				<td>
					成员人数
				</td>
				<td colspan="9">
					<div class="input-group">
						<input v-model="dataForm.copNum" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="memberNum">
						<span class="input-group-addon">户</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					成员中吸纳农户数
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.copFarmerNum" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="memberFarmerNum">
						<span class="input-group-addon">户</span>
					</div>
				</td>
				<td>
					入社农户年均收入
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.farmerIncome" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="memberFarmerYearIncome">
						<span class="input-group-addon">万元</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					带动非社员农户数
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.copUncopNum" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="unmemberFarmerNum">
						<span class="input-group-addon">户</span>
					</div>
				</td>
				<td>
					非社员农户年均收入
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.uncopIncome" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="unmemberFarmerYearIncome">
						<span class="input-group-addon">万元</span>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="10" class="title">
					合作社经营与发展
				</td>
			</tr>
			<tr>
				<td>
					合作社成员培训投入总额
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.copTrainInvest" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="trainInput">
						<span class="input-group-addon">万元/年</span>
					</div>
				</td>
				<td>
					合作社成员培训次数
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.trainNum" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="trainNum">
						<span class="input-group-addon">次/年</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					合作社成员按照生产技术操作规程开展生产的比例
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.copWorkRate" onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');if(isNaN(value))execCommand('undo');" type="text" class="form-control" name="rightProductProportion">
						<span class="input-group-addon">%</span>
					</div>
				</td>
				<td>
					合作社林产品商标注册
				</td>
				<td colspan="4">
					<div class="input-group">
						<input v-model="dataForm.copBrandNum" onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" class="form-control" name="trademarkRegistration">
						<span class="input-group-addon">个</span>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					是否参与产品质量标准与认证
				</td>
				<td colspan="4">
					<input v-model="dataForm.isQuality" type="radio" value="是" name="ifStandardCertification"><label>是</label>
					<input v-model="dataForm.isQuality" type="radio" value="否" name="ifStandardCertification"><label>否</label>
				</td>
				<td>
					是否参与森林可持续经营认证活动
				</td>
				<td colspan="4">
					<input v-model="dataForm.isContinue"  type="radio" value="是" name="ifSustainableCertification"><label>是</label>
					<input v-model="dataForm.isContinue"  type="radio" value="否" name="ifSustainableCertification"><label>否</label>
				</td>
			</tr>
			<tr>
				<td>负责人:</td>
				<td><input v-model="dataForm.dutyer" name="leadingOfficial" type="text" class="form-control"></td>
				<td colspan="2">填报人:</td>
				<td><input v-model="dataForm.reporter" name="fillPerson" type="text" class="form-control"></td>
				<td colspan="4">填表日期:</td>
				<td><el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="dataForm.reportTime" size="mini" type="datetime" ></el-date-picker></td>
			</tr>
			<tr>
					<td colspan="10" style="">填报说明：本表指标一律保留小数点后两位数。</td>
			</tr>
			</tbody>
    </table>  
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="!viewMode" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
				visible: false,
				viewMode: false,
        dataForm: {
          reportId: 0,
          taskUserId: '',
          dutyer: '',
          reporter: '',
          reportTime: '',
          copName: '',
          createName: '',
          createAge: '',
          createSex: '',
          createEdu: '',
          createPosition: '',
          createIncome: '',
					copType: '',
					copTypeOther: '',
					copTypeValue: '',
          regAssert: '',
          beginYear: '',
          busIncome: '',
          busCost: '',
          isStock: '',
          farmerRate: '',
					moneySource: '',
					moneySourceOther: '',
					moneySourceValue: '',
          govSupport: '',
					mainBus: '',
					mainBusOther: '',
					mainBusValue: '',
          busArea: '',
          saleIncome: '',
          prodProfit: '',
          profitRate: '',
          copNum: '',
          copFarmerNum: '',
          farmerIncome: '',
          copUncopNum: '',
          uncopIncome: '',
          copTrainInvest: '',
          trainNum: '',
          copWorkRate: '',
          copBrandNum: '',
          isQuality: '',
          isContinue: ''
        },
        dataRule: {
          
        }
      }
    },
    methods: {
      init (taskUserId, reportId, mode) {
				if(mode == 'view'){
					this.viewMode = true;
				}else{
					this.viewMode = false;
				}
        this.dataForm.reportId = reportId || 0
        this.dataForm.taskUserId = taskUserId || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.reportId) {
            this.$http({
              url: this.$http.adornUrl(`/frt/copreport3/info/${this.dataForm.reportId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.taskUserId = data.copreport3.taskUserId
                this.dataForm.dutyer = data.copreport3.dutyer
                this.dataForm.reporter = data.copreport3.reporter
                this.dataForm.reportTime = data.copreport3.reportTime
                this.dataForm.copName = data.copreport3.copName
                this.dataForm.createName = data.copreport3.createName
                this.dataForm.createAge = data.copreport3.createAge
                this.dataForm.createSex = data.copreport3.createSex
                this.dataForm.createEdu = data.copreport3.createEdu
                this.dataForm.createPosition = data.copreport3.createPosition
                this.dataForm.createIncome = data.copreport3.createIncome
								this.dataForm.copType = data.copreport3.copType
								
								if(data.copreport3.copTypeOther == 'true'){
									this.dataForm.copTypeOther = true
									this.dataForm.copTypeValue = data.copreport3.copTypeValue
								}else{
									this.dataForm.copTypeOther = false
									this.dataForm.copTypeValue = ''
								}
								
                this.dataForm.regAssert = data.copreport3.regAssert
                this.dataForm.beginYear = data.copreport3.beginYear
                this.dataForm.busIncome = data.copreport3.busIncome
                this.dataForm.busCost = data.copreport3.busCost
                this.dataForm.isStock = data.copreport3.isStock
								this.dataForm.farmerRate = data.copreport3.farmerRate
								
								this.dataForm.moneySource = data.copreport3.moneySource
								if(data.copreport3.moneySourceOther == 'true'){
									this.dataForm.moneySourceOther = true
									this.dataForm.moneySourceValue = data.copreport3.moneySourceValue
								}else{
									this.dataForm.moneySourceOther = false
									this.dataForm.moneySourceValue = ''
								}
								
								this.dataForm.govSupport = data.copreport3.govSupport
								
								this.dataForm.mainBus = data.copreport3.mainBus
								if(data.copreport3.mainBusOther == 'true'){
									this.dataForm.mainBusOther = true
									this.dataForm.mainBusValue = data.copreport3.mainBusValue
								}else{
									this.dataForm.mainBusOther = false
									this.dataForm.mainBusValue = ''
								}

                this.dataForm.busArea = data.copreport3.busArea
                this.dataForm.saleIncome = data.copreport3.saleIncome
                this.dataForm.prodProfit = data.copreport3.prodProfit
                this.dataForm.profitRate = data.copreport3.profitRate
                this.dataForm.copNum = data.copreport3.copNum
                this.dataForm.copFarmerNum = data.copreport3.copFarmerNum
                this.dataForm.farmerIncome = data.copreport3.farmerIncome
                this.dataForm.copUncopNum = data.copreport3.copUncopNum
                this.dataForm.uncopIncome = data.copreport3.uncopIncome
                this.dataForm.copTrainInvest = data.copreport3.copTrainInvest
                this.dataForm.trainNum = data.copreport3.trainNum
                this.dataForm.copWorkRate = data.copreport3.copWorkRate
                this.dataForm.copBrandNum = data.copreport3.copBrandNum
                this.dataForm.isQuality = data.copreport3.isQuality
                this.dataForm.isContinue = data.copreport3.isContinue
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/frt/copreport3/${!this.dataForm.reportId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'reportId': this.dataForm.reportId || undefined,
                'taskUserId': this.dataForm.taskUserId,
                'dutyer': this.dataForm.dutyer,
                'reporter': this.dataForm.reporter,
                'reportTime': this.dataForm.reportTime,
                'copName': this.dataForm.copName,
                'createName': this.dataForm.createName,
                'createAge': this.dataForm.createAge,
                'createSex': this.dataForm.createSex,
                'createEdu': this.dataForm.createEdu,
                'createPosition': this.dataForm.createPosition,
                'createIncome': this.dataForm.createIncome,
								'copType': this.dataForm.copType,
								'copTypeOther': this.dataForm.copTypeOther,
								'copTypeValue': this.dataForm.copTypeValue,
                'regAssert': this.dataForm.regAssert,
                'beginYear': this.dataForm.beginYear,
                'busIncome': this.dataForm.busIncome,
                'busCost': this.dataForm.busCost,
                'isStock': this.dataForm.isStock,
                'farmerRate': this.dataForm.farmerRate,
								'moneySource': this.dataForm.moneySource,
								'moneySourceOther': this.dataForm.moneySourceOther,
								'moneySourceValue': this.dataForm.moneySourceValue,
                'govSupport': this.dataForm.govSupport,
								'mainBus': this.dataForm.mainBus,
								'mainBusOther': this.dataForm.mainBusOther,
								'mainBusValue': this.dataForm.mainBusValue,
                'busArea': this.dataForm.busArea,
                'saleIncome': this.dataForm.saleIncome,
                'prodProfit': this.dataForm.prodProfit,
                'profitRate': this.dataForm.profitRate,
                'copNum': this.dataForm.copNum,
                'copFarmerNum': this.dataForm.copFarmerNum,
                'farmerIncome': this.dataForm.farmerIncome,
                'copUncopNum': this.dataForm.copUncopNum,
                'uncopIncome': this.dataForm.uncopIncome,
                'copTrainInvest': this.dataForm.copTrainInvest,
                'trainNum': this.dataForm.trainNum,
                'copWorkRate': this.dataForm.copWorkRate,
                'copBrandNum': this.dataForm.copBrandNum,
                'isQuality': this.dataForm.isQuality,
                'isContinue': this.dataForm.isContinue
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss">
			.cop-report3 table {
				border-collapse: collapse;
			}
			
			.cop-report3 td {
				vertical-align: middle;
				display: table-cell;
				border: solid 1px #ccc;
			}
			
			.cop-report3 .title {
				text-align: center;
			}
			.cop-report3 .yw-group{
				border: solid 1px #ccc;padding: 10px 10px 0px;
			}
			.cop-report3 .yw-group .input-group{
				margin-bottom: 10px;
			}
			.cop-report3 .group-no-1{
				float: left;margin-right: 5%;width: 45%;
			}

</style>
